package com.ly.hotel.spainterface.jg.view;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ly.hotel.R;

/**
 * Created by ThinkPad on 2018/1/29.
 */

public class CustomLoadingDialog {

    CustomCircleRing mLoadingView;
    Dialog mLoadingDialog;

    public CustomLoadingDialog(Context context, String msg){
        // 获得自定义圆环View
        View view = LayoutInflater.from(context).inflate(R.layout.jg_custom_loading_dialog,null);
        // 获取整个布局
        LinearLayout layout = (LinearLayout) view.findViewById(R.id.dialog_view);
        // 获取自定义圆环
        mLoadingView =(CustomCircleRing) view.findViewById(R.id.custom_circle_ring);
        // 获取加载文字
        TextView loadingText = (TextView) view.findViewById(R.id.loading_text);
        loadingText.setText(msg);
        mLoadingDialog = new Dialog(context,R.style.loading_dialog);
        mLoadingDialog.setCancelable(false);
        mLoadingDialog.setContentView(layout);

    }

    public void show(){
        mLoadingDialog.show();
        mLoadingView.startAnim();
    }

    public void close(){
        if(mLoadingDialog != null){
            mLoadingView.stopAnim();
            mLoadingDialog.dismiss();
            mLoadingDialog = null;
        }
    }
}
